package com.lin.sunnyweather.utils

object VersionUtils {
    /**
     * 判断version2是否大于version1
     * 版本号规则 <major>.<minor>.<point>
     */
    fun isNew(version1: String, version2: String): Boolean {
        val elements1 = version1.split('.')
        val elements2 = version2.split('.')
        val elements1Length = elements1.count()
        val elements2Length = elements2.count()
        if (elements1Length <= 0 || elements1Length > 3)
            return false
        if (elements2Length <= 0 || elements2Length > 3)
            return false

        val lastExplicitValue =
            if (elements1Length > elements2Length) elements2Length else elements1Length
        for (i in 0 until lastExplicitValue) {
            if (elements2[i] > elements1[i])
                return true
        }
        return false
    }
}